//
//  CommonAPI.m
//  smile_text
//
//  Created by lanou3g on 15-3-25.
//  Copyright (c) 2015年 线线工厂. All rights reserved.
//

#import "CommonAPI.h"
#import "ResolveData.h"
#import "jokeModel.h"
#import "picModel.h"
#import "womenModel.h"
#import "videoModel.h"
#import "petModel.h"

@implementation CommonAPI
//返回首页笑话资源
+ (void)firstJokeListData:(DataBlock)data
{
    NSMutableArray *jokeData = [NSMutableArray array];
    [ResolveData resolveDataWithUrlStr:FIRSTJOKE setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            jokeModel *m = [[jokeModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
            [jokeData addObject:m];
        }
        data(jokeData);
    }];
    
}
//返回下拉笑话资源
+ (void)downJokeListstring:(NSString*)aString Data:(DataBlock)data
{
    NSMutableArray *downJoke = [NSMutableArray array];
    
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DOWNJOKE,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic) {
            
                jokeModel *m = [[jokeModel alloc]init];
                [m setValuesForKeysWithDictionary:dic];
                [downJoke addObject:m];
            
            
            
        }
        data(downJoke);

        }];
}
//返回日期笑话资源
+ (void)dateJokeListstring:(NSString *)aString Data:(DataBlock)data
{
    NSMutableArray *dateJoke = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:FIRSTIMG setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            jokeModel *m = [[jokeModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
            [dateJoke addObject:m];
        }
        data(dateJoke);
        
    }];

}



//返回首页搞笑图片资源
+ (void)firstImgListData:(DataBlock)data
{
    NSMutableArray *imgData = [NSMutableArray array];
    [ResolveData resolveDataWithUrlStr:FIRSTIMG setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
            
                }
            else
            {
                picModel *m = [[picModel alloc]init];
                [m setValuesForKeysWithDictionary:dic];
                [imgData addObject:m];}
            }
        data(imgData);
    }];

    
}
//返回下拉搞笑图片资源
+ (void)downImgListstring:(NSString*)aString Data:(DataBlock)data
{
    NSMutableArray *downImg = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DOWNIMG,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic) {
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            picModel *m = [[picModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [downImg addObject:m];}
        }
        data(downImg);
        
    }];
}
//返回日期搞笑图文资源
+ (void)dateImgListstring:(NSString*)aString Data:(DataBlock)data
{
    NSMutableArray *dateImg = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DATEIMG,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            picModel *m = [[picModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [dateImg addObject:m];}
        }
        data(dateImg);
        
    }];
    
}

//返回首页美女图片资源
+ (void)firstGirlListData:(DataBlock)data
{
    NSMutableArray *grilData = [NSMutableArray array];
    [ResolveData resolveDataWithUrlStr:FIRSTGIRL setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            womenModel *m = [[womenModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [grilData addObject:m];}
        }
        data(grilData);
    }];

}
//返回下拉美女图片资源
+ (void)downGirlListstring:(NSString*)aString Data:(DataBlock)data
{
    NSMutableArray *downGril = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DOWNGIRL,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic) {
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            womenModel *m = [[womenModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [downGril addObject:m];}
        }
        data(downGril);
        
    }];
}
//返回日期美女图片资源
+ (void)dateGirlListstring:(NSString*)aString Data:(DataBlock)data
{
    NSMutableArray *dateGril = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DATEGIRL,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            womenModel *m = [[womenModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [dateGril addObject:m];}
        }
        data(dateGril);
        
    }];

}

//返回首页视频资源
+ (void)firstVideoListData:(DataBlock)data
{
    
    NSMutableArray *videoData = [NSMutableArray array];
    [ResolveData resolveDataWithUrlStr:FIRSTVIDEO setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            videoModel *m = [[videoModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [videoData addObject:m];}
        }
        data(videoData);
    }];
    
}
//返回下拉视频资源
+ (void)downVideoListstring:(NSString*)aString Data:(DataBlock)data
{ 
    NSMutableArray *dateGril = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DOWNVIDEO,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic) {
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            
            videoModel *m = [[videoModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [dateGril addObject:m];}
        }
        data(dateGril);
        
    }];
}
//返回日期视频资源
+ (void)dateVideoListstring:(NSString*)aString Data:(DataBlock)data 
{
    NSMutableArray *dateGril = [NSMutableArray array];
    
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"%@%@",DATEVIDEO,aString] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        NSDictionary *tempDic = (NSDictionary *)obj;
        for (NSDictionary *dic in tempDic[@"rows"]) {
            
            NSString *cant = @"http://t1.qpic.cn/mblogpic/1ee497794a551d9b6d9a/2000";
            
            NSString *picc = [dic objectForKey:@"pic"];
            
            if ([picc isEqualToString:cant])
            {
                
            }
            else
            {

            videoModel *m = [[videoModel alloc]init];
            [m setValuesForKeysWithDictionary:dic];
                [dateGril addObject:m];}
        }
        data(dateGril);
        
    }];
}

//返回萌宠资源
+ (void)firstPetListNumber:(NSInteger)num Data:(DataBlock)data
{
    NSMutableArray *dataPet = [NSMutableArray array];
    [ResolveData resolveDataWithUrlStr:[NSString stringWithFormat:@"http://joke.luckyamy.com/api/?cat=pic&p=%ld&ap=pet",num] setHTTPMethod:@"GET" postBody:nil resolveBlock:^(id obj) {
        
        NSArray *tempArr = (NSArray *)obj;
        for (NSDictionary *dic in tempArr) {
            
            //判定如果有视频就不把数据存入数组
            NSString *cant = [dic objectForKey:@"playurl"];
            if (cant) {
                
            }else{
                //判定如果有图片尺寸 才把数据加入数组
                NSString *pic = [dic objectForKey:@"width"];
                if (pic) {
                    petModel *m = [[petModel alloc]init];
                    [m setValuesForKeysWithDictionary:dic];
                    [dataPet addObject:m];}
                
            }
            
        }
        data(dataPet);
    }];
}


@end
